package com.spider.site.dao.impl;

import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.spider.site.dao.SpiderHistoryResultDao;
import com.spider.site.dao.base.BaseDao;
import com.spider.site.entity.SpiderHistoryResult;

@Repository
public class SpiderHistoryResultDaoImpl extends BaseDao<SpiderHistoryResult> implements SpiderHistoryResultDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<SpiderHistoryResult> getSpiderHistoryResultBySid(long sid) {
		return super.entityManager
				.createQuery(" FROM SpiderHistoryResult WHERE spiderResultId = :sid ORDER BY id DESC ").setParameter("sid", sid)
				.getResultList();
	}

	@Override
	public boolean addSpiderHistoryResult(SpiderHistoryResult spiderHistoryResult) {
		return super.save(spiderHistoryResult);
	}

	@Override
	public boolean editSpiderHistoryResult(SpiderHistoryResult spiderHistoryResult) {
		return super.update(spiderHistoryResult);
	}

	@Override
	public SpiderHistoryResult getSpiderHistoryResultByIdAndDate(long id, Date history) {
		return (SpiderHistoryResult) super.entityManager.createQuery(" FROM SpiderHistoryResult WHERE spiderResultId = :sid AND spinDate = :history ")
				.setParameter("sid", id).setParameter("history", history).getSingleResult();
	}

}
